package com.trainoo.payment.mock.util;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Random;

/**
 * <p> add description here </p>
 *
 * @author tao.zhou
 * @version 1.0
 * @date 2021/12/2 16:56:00
 */
public class TransIdUtil {

    private static final String PAY_PREFIX = "40";
    private static final String REFUND_PREFIX = "50";

    public static String getPayTransId(){
        return getTransId(PAY_PREFIX);
    }

    public static String getRefundTransId(){
        return getTransId(REFUND_PREFIX);
    }

    private static String getTransId(String prefix) {
        StringBuffer sb = new StringBuffer();
        SimpleDateFormat sdf = new SimpleDateFormat("yyMMddHHmmssSSS");
        sb.append(prefix);
        sb.append(sdf.format(new Date()));
        for (int i=0; i<6; i++) {
            Random random = new Random();
            int nextInt = random.nextInt(10);
            sb.append(nextInt);
        }
        return sb.toString();
    }
}
